<template>
    <div class="card-item" :class="{'hide-header': hideHeader}">
        <div 
        class="header" 
        ref="head"
        v-if="!hideHeader"
        >
            <div class="left">
                <div 
                v-if="icon"
                class="icon"
                >
                    <img 
                        :src="icon" 
                        :alt="title"
                    />
                </div>

                <div 
                v-if="title"
                class="title"
                >
                    {{title}}
                </div>
                <slot name="header-prepend"></slot>
            </div>

            <div class="center">
                <slot name="header"></slot>
            </div>

            <div class="right">
                <slot name="header-append"></slot>
            </div>
        </div>

        <div 
        class="body" 
        :style="bodyStyle"
        >
            <slot></slot>
        </div>

        <div class="footer">

        </div>
    </div>
</template>

<script>
export default {
    props: {
        icon: {
            type: String,
            default: '',
        },
        title: {
            type: String,
            default: '',
        },
        bodyHeight: {
            type: Number,
            default: 0,
        },
        hideHeader: {
            type: Boolean,
            default: false,
        },
    },
    data() {
        return {
            
        };
    },
    computed: {
        bodyStyle() {
            var bodyHeight = this.bodyHeight,
                style = {};

            if (bodyHeight) {
                style.height = `${bodyHeight}px`;
                style.overflowY = 'auto';
            }

            return style;
        },
    },
    methods: {
        
    },
    mounted() {
        
    },
    beforeDestroy() {
        
    },
};
</script>

<style lang="scss" scoped>
    .card-item {
        display: flex;
        flex-direction: column;
        background: white;

        .header{
            display: flex;
            align-items: center;
            height: 54px;
            border-bottom: 1px solid #eeeeee;
            padding: 0 20px;
            cursor: default;

            .left{
                display: flex;
                align-items: center;

                .icon{
                    margin-right: 8px;
                    img{
                        display: block;
                        width: 21px;
                        height: 21px;
                    }
                }

                .title{
                    font-size: 16px;
                    color: #2d2d2d;
                    font-weight: bold;
                }
            }

            .center{
                flex: 1;
                margin-left: 25px;
            }
        }

        .body{
            padding: 10px 20px 30px;
            overflow: hidden;
        }

        & + .card-item{
            margin-top: 20px;
        }

        &.hide-header{
            .body{
                padding-top: 30px;
            }
        }
    }
</style>
